<template>
    <view class="dutyPerson">
        <view class="title">
            <image :src="imgSrc"></image>
            <view>{{ title }}</view>
        </view>
        <view class="content">
            <view v-for="(item, index) in more ? list : list.slice(0, 2)" :key="index" class="content-item">
                <view :class="['content-item-box', index % 2 == 0 && list.length != 1 ? 'borderRight' : '']">
                    <view class="realName">{{ item.realName }}</view>
                    <image src="@/static/images/callPhone.svg" mode="" @click="dial(item)">
                    </image>
                </view>
            </view>
        </view>
        <view class="shrink" v-if="list.length > 2">
            <view @click="shrink">
                <uni-icons :type="more ? 'arrowup' : 'arrowdown'" size="16" color="#999;"></uni-icons>
                {{ more? '向上收起': '向下展开' }}
            </view>
        </view>
    </view>
</template>

<script>
export default {
	props: {
		list: {
			type: Array,
			default: () => []
		},
		title: {
			type: String,
			default: ''
		},
		imgSrc: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			// 展开 收起
			more: false, 
		};
	},
	methods: {
		shrink() {
			this.more = !this.more;
		},
		dial(item) {
			uni.showModal({
				title: '拨打电话',
				content: item.phone,
				success: (res) => {
					if (res.confirm) {
						uni.makePhoneCall({
							phoneNumber: item.phone
						});
					}
				}
			});
		}
	},
};
</script>

<style lang="scss">
.dutyPerson {
    background-color: #fff;
    margin-bottom: 20rpx;
    padding: 20rpx;
    padding-left: 28rpx;

    .title {
        display: flex;
        align-items: center;
        font-size: 32rpx;
        color: #333;
        font-weight: bold;

        image {
            width: 48rpx;
            height: 48rpx;
            margin-right:12rpx;
        }
    }

    .content {
        display: flex;
        flex-wrap: wrap;

        &-item {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 50%;
            margin-top: 20rpx;

            &-box {
                width: 100%;
                display: flex;
                color: #333333;
                justify-content: space-around;
                .realName{
                    width: 100rpx;
                    text-align: center;
                }
            }

            image {
                width: 40rpx;
                height: 40rpx;
            }
        }
    }

    .shrink {
        display: flex;
        justify-content: center;
        align-items: center;
        color: #999999;
        font-size: 26rpx;
        margin-top: 30rpx;
    }

    .borderRight {
        border-right: 1px solid #d8d8d8;
    }
}
</style>